package com.digitalchina.lxnsy.viewholder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.ConsultVO;
import com.digitalchina.lxnsy.toolkit.JointImageUrl;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;

import java.util.ArrayList;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/7/17 11:10
 * 修改备注：
 * ================================================
 */

public class ConsultListHolder extends BaseViewHolder<ConsultVO> {

    private TextView tvNameConsult;
    private TextView tvNameReply;
    private TextView tvTimeConsult;
    private TextView tvTimeReply;
    private TextView tvConsult;
    private TextView tvReply;
    private NineGridView nineGridView;


    public ConsultListHolder(ViewGroup parent) {
        super(parent, R.layout.item_consult_list);
        tvNameConsult = $(R.id.tv_name_consult);
        tvNameReply = $(R.id.tv_name_reply);
        tvTimeConsult = $(R.id.tv_time_consult);
        tvTimeReply = $(R.id.tv_time_reply);
        tvConsult = $(R.id.tv_consult);
        tvReply = $(R.id.tv_reply);
        nineGridView = $(R.id.nineGrid);
    }

    @Override
    public void setData(ConsultVO data) {
        super.setData(data);

        tvConsult.setText(data.getConsultContent());
        if (data.getConsultMen() != null)
            tvNameConsult.setText(data.getConsultMen().getMobilePhone());
        tvTimeConsult.setText(data.getConsultTime());

        if (StringUtil.isStrEmpty(data.getReplyContent()))
            tvReply.setText("等待回复");
        else
            tvReply.setText(data.getReplyContent());

        if (data.getReplyMen() != null)
            tvNameReply.setText(data.getReplyMen().getMobilePhone());
        tvTimeReply.setText(data.getReplyTime());

        ArrayList<ImageInfo> imageInfo = new ArrayList<>();
        if (data.getPictureList() != null && data.getPictureList().size() > 0) {
            nineGridView.setVisibility(View.VISIBLE);
            for (int i = 0; i < data.getPictureList().size(); i++) {
                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(JointImageUrl.smallImageUrl(data.getPictureList().get(i).getPictureVideoId()));
                info.setBigImageUrl(JointImageUrl.bigImageUrl(data.getPictureList().get(i).getPictureVideoId()));
                imageInfo.add(info);
            }
        } else {
            nineGridView.setVisibility(View.GONE);
        }

        nineGridView.setAdapter(new NineGridViewClickAdapter(getContext(), imageInfo));

    }

}
